<?php

namespace View;

require_once ('View/NavigationView.php');

class MovieView {
	
	private $m_name = 'name';
	private $m_review = 'review';
	private $m_rating = 'rating';
	private $m_upload = 'upload';
	private $m_addMovieButton = 'addMovieButton';
	private $m_editButton = 'editButton';
	private $m_saveChangesButton = 'saveChangesButton';
	

	//Returnerar formulär för att lägga till en film
	public function AddMovieBox(){
		
		if (isset($_SESSION['name'])&& isset($_POST[$this->m_name])){
			$_SESSION['name'] = $_POST[$this->m_name];
		} else {
			$_SESSION['name'] = "";
		}
		if (isset($_SESSION['review'])&& isset($_POST[$this->m_review])){
			$_SESSION['review'] = $_POST[$this->m_review];
		} else {
			$_SESSION['review'] = "";
		}
		if (isset($_SESSION['rating'])&& isset($_POST[$this->m_rating])){
			$_SESSION['rating'] = $_POST[$this->m_rating];
		} else {
			$_SESSION['rating'] = "";
		}
		return
		'<div id="movieform">
			<form method="post" enctype="multipart/form-data">
				    <fieldset>
						<label class="label">Title</label> 
						<input type="text" name="'.$this->m_name.'" value="'.$_SESSION['name'].'" />
						<label class="label">Review</label> 
						<textarea name="'.$this->m_review.'" rows="7" cols="30">'.$_SESSION['review'].'</textarea>
						<label class="label">Rating</label> 
						<input type="text" size="1" name="'.$this->m_rating.'" value="'.$_SESSION['rating'].'" />
						<label class="label">Image</label> 
						<input type="file" name ="'.$this->m_upload.'">
						<input type="submit" value="Add movie" id="moviebutton" name="'.$this->m_addMovieButton.'"/>
					</fieldset>
			 </form>
		 </div>';	
	 }
	 //Returnerar formulär för att redigera en film
	 public function EditMovieBox($movie){
			
		$name = $movie->getName();
		$review = $movie->getReview();
		$rating = $movie->getRating();
		
		return
		 '<div id="movieform">
			<form method="post">
				    <fieldset>
						<label class="label">Title</label> 
						<input type="text" name="'.$this->m_name.'" value="'.$name.'" />
						<label class="label">Review</label> 
						<textarea name="'.$this->m_review.'" rows="7" cols="30">'.$review.'</textarea>
						<label class="label">Rating</label> 
						<input type="text" size="1" name="'.$this->m_rating.'" value="'.$rating.'" />
						<input type="submit" value="Save changes" id="moviebutton" name="'.$this->m_saveChangesButton.'"/>
					</fieldset>
			 </form>
		 </div>';	
		
	}
	
	public function EditMovieButton(){
		return
		'<form method="post">
					<input type="submit" value="Edit movie" id="editbutton" name="'.$this->m_editButton.'"/>
			</form>';
	}
	
	
	//Har användaren klickat på edit
	public function TriedToEdit(){
		
		if (isset($_POST[$this->m_editButton])){
			return true;
		}
		return false;
	}
	 //Har användaren klickat på lägg till
	 public function TriedToAdd() {
		  	if (isset($_POST[$this->m_addMovieButton])) {
		  		return true;
		  		
			}
			else {
				return false;
			}
	 }
	 //Har användaren klickat på spara ändringar
	 public function TriedToSaveChanges(){
		
		if (isset($_POST[$this->m_saveChangesButton])){
			return true;
		}
		return false;
	}
	//Returnerar namnet
	public function GetName(){
		if(isset($_POST[$this->m_name])){
			return $_POST[$this->m_name];
		}
	 }
	 //Returnerar omdöme
	 public function GetReview(){
		if(isset($_POST[$this->m_review])){
			return $_POST[$this->m_review];
		}
	 }
	 //Returnerar betyg
	 public function GetRating(){
		if(isset($_POST[$this->m_rating])){
			return $_POST[$this->m_rating];
		}
	 }
	 //Returnerar upload
	 public function GetUpload(){
		if(isset($_POST[$this->m_upload])){
			return $_POST[$this->m_upload];
		}
	 }
	 //Rättmeddelande
	 public function AddMovieSuccess(){
	 	$message = "<p id='movieSuccess'>Movie added!</p>";
	 	return $message;
	 }
	 //Rättmeddelande
	 public function EditMovieSuccess(){
	 	$message = "<p id='movieSuccess'>Movie edited!</p>";
	 	return $message;
	 }
	 
	 
	 public function MovieExistMessage(){
	 	$message = "<p id='movieSuccess'>Movie is already added!</p>";
	 	return $message;
	 }
}
?>